﻿using Microsoft.ManagementConsole.Controls;
using Microsoft.ManagementConsole.SnapIns.Integration;
using PlanckTime.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Microsoft.ManagementConsole.SnapIns.Controls
{
    [SnapInSettings(PlanckTimeSnapIn.PlanckTimeSnapInGuid,
    Vendor = PlanckTimeSnapIn.Vendor,
    Description = PlanckTimeSnapIn.Description,
    DisplayName = PlanckTimeSnapIn.DisplayName)]
    public class PlanckTimeSnapIn : SnapIn
    {
        #region Fields&Properties

        public const string PlanckTimeSnapInGuid = "{a5345fdd-d497-4884-b200-6da3c3ddbf8b}";
        public const string Vendor = "VeriPark";
        public const string DisplayName = "Project";
        public const string Description = "";

        #endregion

        #region Methods

        public PlanckTimeSnapIn()
        {
            LoginForm loginForm = new LoginForm();

            loginForm.ShowDialog();
        
            if (loginForm.IsValidLogin)
            {
            var collection = PlanckTimeServices.Instance.GetTasks(new Task());

            Task[] tasks = collection.ConvertTo<Task>();

            this.RootNode = new PlanckTimeNode(new Guid());
            
            this.RootNode.DisplayName = "Veripark";

            foreach (var item in tasks)
            {
                var node = new PlanckTimeNode(item.Id);
                node.Tag = item;
                node.DisplayName = item.Name;
                node.EnabledStandardVerbs = StandardVerbs.Properties;
                this.RootNode.Children.Add(node);
            }
            }

        }
        #endregion
    }
}
